﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using LGE;
using Microsoft.Xna.Framework;

namespace YouOnlyGetOne
{
    class Arrow : GameObject
    {
        public static List<Texture2D> Textures = new List<Texture2D>();

        int velocity = 10;
        SpriteSheet ss;

        double invTimer = 0;
        int invDuration = 200;

        public Arrow(PlayScreen ps, Vector2 position, Vector2 direction)
            : base(ps, GameObject.tile)
        {
            this.position = position;
            this.direction = direction;
            sprite = Textures[Rand.Next(4)];
            ss = new SpriteSheet(this, 68, 28, 100, true);

            sourceRectangle = new Rectangle(0, 0, 68, 28);
            HitBox = new Rectangle(0, 0, 20, 20);
            origin = new Vector2(sourceRectangle.Width / 2, sourceRectangle.Height / 2);
        }

        public override void Update(GameTime gameTime)
        {
            ss.Update(gameTime);
            speed = direction * velocity;

            if (Collision(ps.player))
            {
                Audio.PlayCue("arrow_hit");
                ps.player.stunTimer = 0;
                ps.player.coins -= 1;
                if (ps.player.coins < 0) ps.player.coins = 0;
                alive = false;
            }


            if (invTimer < invDuration)
            {
                invTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
                position += speed;
            }
            else
                if (CheckCollisionWithMap(MapManager.CollisionLayer)) alive = false;


        }
    }
}
